﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using Microsoft.Practices.CompositeUI.UIElements;

namespace WPFCABShell.Shell.Services.ToolBar
{
	/// <summary>
	/// A <see cref="IUIElementAdapterFactory"/> that produces adapters for <see cref="ToolBarTray"/>s.
	/// </summary>
	public sealed class ToolBarTrayUIAdapterFactory : IUIElementAdapterFactory
	{
		/// <summary>
		/// Gets an adapter for <paramref name="uiElement"/>.
		/// </summary>
		/// <param name="uiElement">
		/// The UI element for which an adapter is required.
		/// </param>
		/// <returns>
		/// The UI element adapter.
		/// </returns>
		public IUIElementAdapter GetAdapter(object uiElement)
		{
			ToolBarTray toolBarTray = uiElement as ToolBarTray;

			if (toolBarTray != null)
			{
				return new ToolBarTrayUIAdapter(toolBarTray);
			}

			throw new ArgumentException("uiElement is not a ToolBarTray.", "uiElement");
		}

		/// <summary>
		/// Gets a value indicating whether this adapter factory can adapt <paramref name="uiElement"/>.
		/// </summary>
		/// <param name="uiElement">
		/// The UI element that requires adapting.
		/// </param>
		/// <returns>
		/// <see langword="true"/> if <paramref name="uiElement"/> can be adapted by this adapter factory, otherwise
		/// <see langword="false"/>.
		/// </returns>
		public bool Supports(object uiElement)
		{
			return uiElement is ToolBarTray;
		}
	}
}
